/*****************************************************
*                                                                          
*               COPYRIGHT (c) 2015-2017 Hargic Corporation              
*                         All Rights Reserved                              
*                                                                          
* The source code contained or described herein and all documents          
* related to the source code ("Material") are owned by Hargic         
* Corporation or its licensors.  Title to the Material remains             
* with Hargic Corporation or its suppliers and licensors.               
*                                                                          
* The Material is protected by worldwide copyright and trade secret        
* laws and treaty provisions. No part of the Material may be used,         
* copied, reproduced, modified, published, uploaded, posted, transmitted,  
* distributed, or disclosed in any way except in accordance with the       
* applicable license agreement.                                            
*                                                                          
* No license under any patent, copyright, trade secret or other            
* intellectual property right is granted to or conferred upon you by       
* disclosure or delivery of the Materials, either expressly, by            
* implication, inducement, estoppel, except in accordance with the         
* applicable license agreement.                                            
*                                                                          
* Unless otherwise agreed by Hargic in writing, you may not remove or   
* alter this notice or any other notice embedded in Materials by Hargic 
* or Hargic's suppliers or licensors in any way.                        
*                                                                          
** Author: ted.huang
** Date: 2018-03-03
*
*****************************************************/

#ifndef __PROTOCOL_H_
#define __PROTOCOL_H_

#ifdef __cplusplus
extern "C"{
#endif

/***** INCLUDES *************************************/
#include <stdint.h>
	
/***** TYPEDEFS *************************************/

typedef struct 
{
	uint16_t	magic;
	uint8_t 	pid;
	uint8_t 	did;
	uint8_t 	reserve;
	uint8_t 	cmd;
	uint16_t 	len;
	uint16_t 	version;
	uint16_t 	csum;
} msg_header_t;

typedef struct 
{
	uint8_t		did;
	uint8_t 	status;
} msg_type_led_t;

/***** DEFINES **************************************/

#define MSG_HEADER_MAGIC 			0xDEAD

#define MSG_HEADER_CSUM_OFFSET		0xC0DE

#define MSG_HEADER_SIZEOF			sizeof(msg_header_t)

#define WIRELESS_SEND_BUFFER_SIZE			64
#define WIRELESS_RECV_BUFFER_SIZE			128

enum
{
	MSG_TYPE_CMD_LED_REQ = 100,
	MSG_TYPE_CMD_LED_RESP,
	MSG_TYPE_CMD_MAX,
};

#define MSG_TYPE_LED_STATUS_OFF		0
#define MSG_TYPE_LED_STATUS_ON		1

/***** CONSTANTS ************************************/

/***** VARIABLES ************************************/

/***** EXTERNAL VARIABLES ***************************/
extern uint8_t send_buffer[WIRELESS_SEND_BUFFER_SIZE];
extern uint8_t recv_buffer[WIRELESS_RECV_BUFFER_SIZE];

/***** EXTERNAL FUNCTIONS ***************************/

/***** PROTOTYPES ***********************************/
uint16_t message_handler(uint8_t *data, uint16_t len);;
int16_t message_send(uint16_t cmd, uint8_t *body, uint16_t bodylen);


#ifdef __cplusplus
}
#endif

#endif /* __PROTOCOL_H_ */

